package com.sl.hx.shop.ui.mine.presnter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.widget.TextView;

import com.apkfuns.logutils.LogUtils;
import com.sl.hx.shop.R;
import com.sl.hx.shop.base.BasePresenter;
import com.sl.hx.shop.bean.HeadBean;
import com.sl.hx.shop.bean.HomeBannerBean;
import com.sl.hx.shop.bean.ImageUrlBean;
import com.sl.hx.shop.bean.LoginBean;
import com.sl.hx.shop.bean.MessageBean;
import com.sl.hx.shop.constant.AppConfig;
import com.sl.hx.shop.http.ApiFactory;
import com.sl.hx.shop.http.ApiRetrofit;
import com.sl.hx.shop.http.HttpUtil;
import com.sl.hx.shop.http.ProgressSubscribe;
import com.sl.hx.shop.ui.mine.contacts.LoginContacts;
import com.sl.hx.shop.ui.mine.contacts.MineContacts;
import com.sl.hx.shop.utils.HMACSHA1;
import com.sl.hx.shop.utils.SPUtils;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.android.FragmentEvent;

import java.io.File;
import java.util.List;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class MinePresenter extends BasePresenter<MineContacts.view> implements MineContacts.presenter {


    private Context mContext;

    public MinePresenter(Context context) {
        this.mContext=context;
    }


    public void getHead() {
        Observable observable = ApiFactory.getInstance().getMyhead(SPUtils.getInstance().getString(AppConfig.ID));
        HttpUtil.getInstance().toSubscribe(observable, new ProgressSubscribe<HeadBean>(mContext) {
            @Override
            protected void _onNext(HeadBean headBean) {
                getView().ShowHead(headBean);
                //Log.e("head",headBean.getLogo());
            }
            @Override
            protected void _onError(String message) {

            }
        }, true, getView(), FragmentEvent.DESTROY);
    }


    public void getMessage() {
        Observable observable = ApiFactory.getInstance().getMessage(ApiRetrofit.getCacheControl());
        HttpUtil.getInstance().toSubscribe(observable, new ProgressSubscribe<List<MessageBean>>(mContext) {
            @Override
            protected void _onNext(List<MessageBean> messageBean) {
                getView().ShowMessage(messageBean);
            }
            @Override
            protected void _onError(String message) {

            }
        }, true, getView(), FragmentEvent.DESTROY);
    }
}
